package util.map;

import signal.Signal;

public class MarsMap implements Cloneable {

	private final int SCOPEMAX = 9;
	private final int SCOPEMIN = 1;
	private int x = 5;
	private int y = 5;

	private String dirdes;

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getScope() {
		return SCOPEMAX;
	}

	public MarsMap() {
		x = (int) (Math.random() * 9) + 1;
		y = (int) (Math.random() * 9) + 1;
		dirdes = "从" + "(" + x + "," + y + ")位置出发";
	}

	public String getDirDes() {
		return dirdes;
	}

	public String toString() {
		return "(" + x + "," + y + ")";
	}

	public boolean isMove(Signal s) {
		int temp_x = x;
		int temp_y = y;
		if (isLeagle(s)) {
			return true;
		}

		x = temp_x;
		y = temp_y;
		return false;

	}

	public MarsMap getClone() {
		MarsMap temp = null;
		try {
			temp = (MarsMap) this.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return temp;
	}

	private boolean isLeagle(Signal s) {
		dirdes = "";
		if (s.getIsUp()) {
			++y;
			dirdes = "向前移动1步";
		}

		if (s.getIsDown()) {
			--y;
			dirdes = "向后移动1步";
		}

		if (s.getIsLeft()) {
			--x;
			dirdes = dirdes + "向左移动1步";
		}

		if (s.getIsRight()) {
			++x;
			dirdes = dirdes + "向右移动1步";
		}

		s.initDir();

		if (x > SCOPEMAX || x < SCOPEMIN || y > SCOPEMAX || y < SCOPEMIN) {
			return false;
		}

		return true;
	}

}